// http://interval.cz/clanky/alternativni-styly-zmena-stylu-pomoci-javascriptu/

function createCookie(name,value,days)
{
  if (days)
  {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else var expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name)
{
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++)
  {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
} 

var BASE="#"

function setCSS(title)
{
  var i, p, links = new Array();
  links=document.getElementsByTagName("link");
  for (i=0; i<links.length; i++)
  {
    if ((links[i].getAttribute("rel").indexOf("stylesheet")!=-1) && (p=links[i].getAttribute("title")))
    {
      links[i].disabled=true;
      if ((p==title) && (p!=BASE)) links[i].disabled=false;
    }
  }
  //alert(title);
  createCookie("style", title, 10);
}

function setStyle(txt){
    if (txt=="Svetly styl"){
        createCookie("barvy", "s", 10);
    }
    if (txt=="Tmavy styl"){       
        createCookie("barvy", "t", 10);
    }
    if (txt=="Vertikalni menu"){
        createCookie("typ", "v", 10);
    }
    if (txt=="Horizontalni menu"){
        createCookie("typ", "h", 10);
    }
    
    var tmp = readCookie("barvy") + readCookie("typ");
    if (tmp=="sh"){
        setCSS("Svetle horizontalni menu");
    } 
    if (tmp=="sv"){
        setCSS("Svetle vertikalni menu");
    }
    if (tmp=="th"){
        setCSS("Tmave horizontalni menu");
    } 
    if (tmp=="tv"){
        setCSS("Tmave vertikalni menu");
    }
}

window.onload=function()
{
  if (readCookie("typ") != "h" && readCookie("typ") != "v"){
    createCookie("typ", "v", 10);
  }
  if (readCookie("barvy") != "s" && readCookie("barvy") != "t"){
    createCookie("barvy", "s", 10);
  }

  var p;
  if (p=readCookie("style"))
  {
    setCSS(p);
  }
} 
